home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Round_Cala215421642009.psc / new cal / Container.ctl < prev    next >
Text File  |  2006-08-31  |  24KB  |  770 lines

  1. VERSION 5.00
  2. Begin VB.UserControl IoxContainer 
  3.    Alignable       =   -1  'True
  4.    BorderStyle     =   1  'Fixed Single
  5.    ClientHeight    =   1740
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   1740
  9.    ControlContainer=   -1  'True
  10.    HasDC           =   0   'False
  11.    ScaleHeight     =   116
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   116
  14.    Begin VB.Timer FocusTimer 
  15.       Interval        =   50
  16.       Left            =   0
  17.       Top             =   0
  18.    End
  19.    Begin VB.PictureBox Scrollpic 
  20.       BorderStyle     =   0  'None
  21.       Height          =   240
  22.       Left            =   1500
  23.       ScaleHeight     =   240
  24.       ScaleWidth      =   240
  25.       TabIndex        =   2
  26.       TabStop         =   0   'False
  27.       Top             =   1500
  28.       Width           =   240
  29.    End
  30.    Begin VB.HScrollBar HScroll 
  31.       Height          =   240
  32.       Left            =   0
  33.       Max             =   10
  34.       TabIndex        =   1
  35.       TabStop         =   0   'False
  36.       Top             =   1500
  37.       Width           =   1500
  38.    End
  39.    Begin VB.VScrollBar VScroll 
  40.       Height          =   1500
  41.       Left            =   1500
  42.       Max             =   10
  43.       TabIndex        =   0
  44.       TabStop         =   0   'False
  45.       Top             =   0
  46.       Width           =   240
  47.    End
  48. End
  49. Attribute VB_Name = "IoxContainer"
  50. Attribute VB_GlobalNameSpace = False
  51. Attribute VB_Creatable = True
  52. Attribute VB_PredeclaredId = False
  53. Attribute VB_Exposed = False
  54. Option Explicit
  55. '//////////////////////////////  IOX Container  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  56. 'This is the most advanced container control in PSC.
  57. 'Did you love controls that don't have much "client-side" code...
  58.  
  59. 'Ok, this is a 0 line client-side code control, It┤s a REAL container,
  60. 'You just put controls inside and the contros do the dirty job.
  61. 'Allows to put many controls in the panel, an use scrollbars to acces them
  62. 'This panel suport Mouse Wheel, WITHOUT SUBCLASS, just uses the free time
  63. 'to Peek Messages, so its IDE safe.
  64. 'It has a lot of features, like:
  65. 'Use ScrollBarConstants (vbBoth, vbVertical, vbSBNone, vbHorizontal)
  66. 'Use ScrollBar sensibility
  67. 'Vertical and horizontal margin to ajust the contained controls
  68. 'Change the potion of the scrolls when a contained controls got focus
  69. 'Is aligneable
  70.  
  71. 'I got the idea from IsPanel, By DavidJ, but this is a complete rewrite, so
  72. 'it uses diferent and more eficient programing techniques.
  73.  
  74.  
  75. ' Created by Ivan Tellez
  76. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\  IOX Container  //////////////////////////////
  77.  
  78.  
  79.  
  80. ' API Declarations
  81. ' ==================================
  82. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  83. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  84. Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  85. Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
  86. Private Declare Function WaitMessage Lib "user32" () As Long
  87.  
  88.  
  89.  
  90. ' API Constants
  91. ' ==================================
  92. Private Const PM_REMOVE = &H1
  93.  
  94. Private Type POINTAPI
  95.         x As Long
  96.         Y As Long
  97. End Type
  98.  
  99. Private Type msg
  100.     hWnd As Long
  101.     Message As Long
  102.     wParam As Long
  103.     lParam As Long
  104.     time As Long
  105.     pt As POINTAPI
  106. End Type
  107.  
  108. Private bCancel As Boolean
  109. Private Const WM_MOUSEWHEEL = 522
  110.  
  111.  
  112. Private Const SM_CYVSCROLL = 20
  113.  
  114. Private Type CurrentControlType
  115.         Name As String
  116.         Index As Long
  117. End Type
  118.  
  119. Private Type RECT
  120.         Left As Long
  121.         Top As Long
  122.         Right As Long
  123.         Bottom As Long
  124. End Type
  125.  
  126.  
  127.  
  128.  
  129. ' Control properties
  130. ' ==================================
  131. Public Enum BorderStyleEnum
  132.     [None]
  133.     [Fixed Single]
  134. End Enum
  135.  
  136. Public Enum ScrollBehaviorEnum
  137.     [Normal]
  138.     [Middle]
  139.     [Reverse]
  140. End Enum
  141.  
  142. Public Enum SensibilityEnum
  143.     [Highest]
  144.     [High]
  145.     [Medium]
  146.     [Low]
  147. End Enum
  148.  
  149. Public Enum MarginEnum
  150.     [None] = 0
  151.     [5 pixels] = 5
  152.     [10 pixels] = 10
  153.     [15 pixels] = 15
  154.     [20 pixels] = 20
  155.     [25 pixels] = 25
  156.     [30 pixels] = 30
  157. End Enum
  158.  
  159. 'Default Property Values:
  160. Const m_def_BorderStyle = 1
  161. Const m_def_Enabled = True
  162. Const m_def_ScrollBars = 3
  163. Const m_def_Sensibility = 2
  164. Const m_def_MarginV = 5
  165. Const m_def_MarginH = 5
  166. Const m_def_ScrollBehavior = 0
  167.  
  168. 'Property Variables:
  169. Dim m_BorderStyle As BorderStyleEnum
  170. Dim m_Enabled As Boolean
  171. Dim m_ScrollBars As ScrollBarConstants
  172. Dim m_Sensibility As SensibilityEnum
  173. Dim m_MarginV As MarginEnum
  174. Dim m_MarginH As MarginEnum
  175. Dim m_ScrollBehavior As ScrollBehaviorEnum
  176.  
  177. Private HPrevValue As Long
  178. Private VPrevValue As Long
  179. Private TempControl As Control
  180.  
  181. Private CurrCtrl As CurrentControlType
  182. Private LastCtrl As CurrentControlType
  183.  
  184.  
  185.  
  186.  
  187.  
  188. 'Initialize properties for a new user control
  189. ' ==================================
  190. Private Sub UserControl_InitProperties()
  191.     m_BorderStyle = m_def_BorderStyle
  192.     m_Enabled = m_def_Enabled
  193.     m_ScrollBars = m_def_ScrollBars
  194.     m_Sensibility = m_def_Sensibility
  195.     m_MarginH = m_def_MarginH
  196.     m_MarginV = m_def_MarginV
  197.     m_ScrollBehavior = m_def_ScrollBehavior
  198. End Sub
  199.  
  200. 'Load properties from the PropBag
  201. ' ==================================
  202. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  203.     UserControl.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
  204.     UserControl.BorderStyle = PropBag.ReadProperty("BorderStyle", 1)
  205.     m_Enabled = PropBag.ReadProperty("Enabled", m_def_Enabled)
  206.     m_ScrollBars = PropBag.ReadProperty("ScrollBars", m_def_ScrollBars)
  207.     m_BorderStyle = PropBag.ReadProperty("BorderStyle", m_def_BorderStyle)
  208.     m_Sensibility = PropBag.ReadProperty("Sensibility", m_def_Sensibility)
  209.     m_MarginH = PropBag.ReadProperty("MarginH", m_def_MarginH)
  210.     m_MarginV = PropBag.ReadProperty("MarginV", m_def_MarginV)
  211.     m_ScrollBehavior = PropBag.ReadProperty("ScrollBehavior", m_def_ScrollBehavior)
  212. End Sub
  213.  
  214. 'Save properties from the PropBag
  215. ' ==================================
  216. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  217.     Call PropBag.WriteProperty("BackColor", UserControl.BackColor, &H8000000F)
  218.     Call PropBag.WriteProperty("BorderStyle", UserControl.BorderStyle, 1)
  219.     Call PropBag.WriteProperty("Enabled", m_Enabled, m_def_Enabled)
  220.     Call PropBag.WriteProperty("ScrollBars", m_ScrollBars, m_def_ScrollBars)
  221.     Call PropBag.WriteProperty("Sensibility", m_Sensibility, m_def_Sensibility)
  222.     Call PropBag.WriteProperty("MarginH", m_MarginH, m_def_MarginH)
  223.     Call PropBag.WriteProperty("MarginV", m_MarginV, m_def_MarginV)
  224.     Call PropBag.WriteProperty("ScrollBehavior", m_ScrollBehavior, m_def_ScrollBehavior)
  225. End Sub
  226.  
  227.  
  228.  
  229.  
  230.  
  231. 'User control properties
  232. ' ==================================
  233. Public Property Get BackColor() As OLE_COLOR
  234.     BackColor = UserControl.BackColor
  235. End Property
  236. Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
  237.     UserControl.BackColor() = New_BackColor
  238.     PropertyChanged "BackColor"
  239. End Property
  240.  
  241. Public Property Get Sensibility() As SensibilityEnum
  242.     Sensibility = m_Sensibility
  243. End Property
  244. Public Property Let Sensibility(ByVal New_Sensibility As SensibilityEnum)
  245.     If Ambient.UserMode Then Err.Raise 382
  246.     m_Sensibility = New_Sensibility
  247.     PropertyChanged "Sensibility"
  248. End Property
  249.  
  250. Public Property Get ScrollBehavior() As ScrollBehaviorEnum
  251.     ScrollBehavior = m_ScrollBehavior
  252. End Property
  253. Public Property Let ScrollBehavior(ByVal New_ScrollBehavior As ScrollBehaviorEnum)
  254.     If Ambient.UserMode Then Err.Raise 382
  255.     m_ScrollBehavior = New_ScrollBehavior
  256.     PropertyChanged "ScrollBehavior"
  257. End Property
  258.  
  259. Public Property Get MarginV() As MarginEnum
  260.     MarginV = m_MarginV
  261. End Property
  262. Public Property Let MarginV(ByVal New_MarginV As MarginEnum)
  263.     If Ambient.UserMode Then Err.Raise 382
  264.     m_MarginV = New_MarginV
  265.     PropertyChanged "MarginV"
  266.     UserControl_Resize
  267. End Property
  268.  
  269. Public Property Get MarginH() As MarginEnum
  270.     MarginH = m_MarginH
  271. End Property
  272. Public Property Let MarginH(ByVal New_MarginH As MarginEnum)
  273.     If Ambient.UserMode Then Err.Raise 382
  274.     m_MarginH = New_MarginH
  275.     PropertyChanged "MarginH"
  276.     UserControl_Resize
  277. End Property
  278.  
  279. Public Property Get BorderStyle() As BorderStyleEnum
  280.     BorderStyle = UserControl.BorderStyle
  281. End Property
  282. Public Property Let BorderStyle(ByVal New_BorderStyle As BorderStyleEnum)
  283.     UserControl.BorderStyle() = New_BorderStyle
  284.     PropertyChanged "BorderStyle"
  285. End Property
  286.  
  287. Public Property Get Enabled() As Boolean
  288.     Enabled = m_Enabled
  289. End Property
  290. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  291.     m_Enabled = New_Enabled
  292.     PropertyChanged "Enabled"
  293. End Property
  294.  
  295. Public Property Get hWnd() As Long
  296.     hWnd = UserControl.hWnd
  297. End Property
  298.  
  299. Public Property Get ScrollBars() As ScrollBarConstants
  300.     ScrollBars = m_ScrollBars
  301. End Property
  302. Public Property Let ScrollBars(ByVal New_ScrollBars As ScrollBarConstants)
  303.     m_ScrollBars = New_ScrollBars
  304.     PropertyChanged "ScrollBars"
  305.     UserControl_Resize
  306. End Property
  307.  
  308.  
  309.  
  310. 'User control methods
  311. ' ==================================
  312. Private Sub UserControl_Terminate()
  313. bCancel = True
  314. FocusTimer = True
  315. End Sub
  316.  
  317. Private Sub UserControl_Show()
  318. UserControl_Resize
  319. FocusTimer.Enabled = True
  320. ProcessMessages
  321. End Sub
  322.  
  323. Private Sub UserControl_Initialize()
  324.     CurrCtrl.Name = ""
  325.     CurrCtrl.Index = 0
  326.     LastCtrl.Name = ""
  327.     LastCtrl.Index = 0
  328.     HPrevValue = 0
  329.     VPrevValue = 0
  330.     HScroll.Value = 0
  331.     VScroll.Value = 0
  332. End Sub
  333.  
  334. Private Sub UserControl_Paint()
  335. If Not Ambient.UserMode Then UserControl_Resize
  336. End Sub
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354. 'Private methods
  355. ' ==================================
  356. Private Sub UserControl_Resize()
  357. On Error Resume Next
  358. Dim ScrollWidth As Long
  359. Dim ScrollHeight As Long
  360.  
  361. ScrollWidth = GetSystemMetrics(SM_CYVSCROLL) '* Screen.TwipsPerPixelX
  362. ScrollHeight = GetSystemMetrics(SM_CYVSCROLL) '* Screen.TwipsPerPixelY
  363. HScroll.Enabled = False
  364. VScroll.Enabled = False
  365.  
  366. With UserControl
  367.     Select Case m_ScrollBars        'Position the controls
  368.         Case vbSBNone
  369.             HScroll.Visible = False
  370.             VScroll.Visible = False
  371.             Scrollpic.Visible = False
  372.         Case vbHorizontal
  373.             HScroll.Visible = True
  374.             VScroll.Visible = False
  375.             Scrollpic.Visible = False
  376.             HScroll.Move 0, .ScaleHeight - ScrollHeight, .ScaleWidth, ScrollHeight
  377.             HScroll.Enabled = (CalcClientWidth > UserControl.ScaleWidth)
  378.         Case vbVertical
  379.             HScroll.Visible = False
  380.             VScroll.Visible = True
  381.             Scrollpic.Visible = False
  382.             VScroll.Move .ScaleWidth - ScrollWidth, 0, ScrollWidth, .ScaleHeight
  383.             VScroll.Enabled = (CalcClientHeight > UserControl.ScaleHeight)
  384.         Case vbBoth
  385.             HScroll.Visible = True
  386.             VScroll.Visible = True
  387.             Scrollpic.Visible = True
  388.             VScroll.Move .ScaleWidth - ScrollWidth, 0, ScrollWidth, .ScaleHeight + (ScrollHeight * -1)
  389.             HScroll.Move 0, .ScaleHeight - ScrollHeight, .ScaleWidth + (ScrollWidth * -1), ScrollHeight
  390.             Scrollpic.Move .ScaleWidth - ScrollWidth, .ScaleHeight - ScrollHeight, ScrollWidth, ScrollHeight
  391.             HScroll.Enabled = (CalcClientWidth > (UserControl.ScaleWidth - VScroll.Width))
  392.             VScroll.Enabled = (CalcClientHeight > (UserControl.ScaleHeight - HScroll.Height))
  393.     End Select
  394.     
  395.     If Ambient.UserMode Then
  396.         CalcScrollValues
  397.     End If
  398.     
  399. End With
  400.  
  401. HScroll.ZOrder
  402. VScroll.ZOrder
  403. Scrollpic.ZOrder
  404. End Sub
  405.  
  406. Private Function CalcClientWidth() As Long
  407. On Error Resume Next
  408. Dim MaxWidth As Long
  409. Dim ctrl As Object
  410. For Each ctrl In UserControl.ContainedControls
  411.     If MaxWidth < (ctrl.Left + ctrl.Width + (m_MarginH)) Then
  412.         MaxWidth = (ctrl.Left + ctrl.Width + (m_MarginH))
  413.     End If
  414. Next
  415. If MaxWidth <> 0 Then
  416.     CalcClientWidth = MaxWidth    'Maximo valor hacia la derecha
  417. Else
  418.     CalcClientWidth = 0 'UserControl.ScaleWidth
  419. End If
  420. End Function
  421.  
  422. Private Function CalcClientHeight() As Long
  423. On Error Resume Next
  424. Dim MaxHeight As Long
  425. Dim ctrl As Object
  426. For Each ctrl In UserControl.ContainedControls
  427.     If MaxHeight < (ctrl.Top + ctrl.Height + (m_MarginV)) Then
  428.         MaxHeight = (ctrl.Top + ctrl.Height + (m_MarginV))
  429.     End If
  430. Next
  431. If MaxHeight <> 0 Then
  432.     CalcClientHeight = MaxHeight    'Max down val
  433. Else
  434.     CalcClientHeight = 0
  435. End If
  436. End Function
  437.  
  438.  
  439. Private Sub CalcScrollValues()
  440. Dim NewMaxVal As Long
  441. Select Case m_ScrollBars 'Position the controls
  442.     Case vbSBNone
  443.     Case vbHorizontal    'Only  horizontal scroll
  444.         With HScroll
  445.             NewMaxVal = CalcClientWidth() - UserControl.ScaleWidth
  446.             If NewMaxVal > 32767 Then NewMaxVal = 32767
  447.             .Max = NewMaxVal
  448.             If .Value > .Max Then .Value = .Max
  449.             .LargeChange = .Max
  450.             Select Case m_Sensibility
  451.                 Case [Highest]
  452.                     .SmallChange = .LargeChange / 20
  453.                 Case [High]
  454.                     .SmallChange = .LargeChange / 15
  455.                 Case [Medium]
  456.                     .SmallChange = .LargeChange / 10
  457.                 Case [Low]
  458.                     .SmallChange = .LargeChange / 5
  459.             End Select
  460.  
  461.         End With
  462.         VScroll.Max = 0
  463.         VScroll.Value = 0
  464.         
  465.     Case vbVertical   'Only  Vertical scroll
  466.         With VScroll
  467.             Dim test As Variant
  468.             NewMaxVal = CalcClientHeight - UserControl.ScaleHeight
  469.             If NewMaxVal > 32767 Then NewMaxVal = 32767
  470.             .Max = NewMaxVal
  471.             If .Value > .Max Then .Value = .Max
  472.             .LargeChange = .Max
  473.             Select Case m_Sensibility
  474.                 Case [Highest]
  475.                     .SmallChange = .LargeChange / 20
  476.                 Case [High]
  477.                     .SmallChange = .LargeChange / 15
  478.                 Case [Medium]
  479.                     .SmallChange = .LargeChange / 10
  480.                 Case [Low]
  481.                     .SmallChange = .LargeChange / 5
  482.             End Select
  483.             If .Value > .Max Then .Value = .Max
  484.         End With
  485.         HScroll.Max = 0
  486.         HScroll.Value = 0
  487.         
  488.     Case vbBoth     'Both scrolls
  489.         With HScroll
  490.             NewMaxVal = CalcClientWidth - (UserControl.ScaleWidth - VScroll.Width)
  491.             If NewMaxVal > 32767 Then NewMaxVal = 32767
  492.             .Max = NewMaxVal
  493.             If .Value > .Max Then .Value = .Max
  494.             .LargeChange = .Max / 2
  495.             Select Case m_Sensibility
  496.                 Case [Highest]
  497.                     .SmallChange = .LargeChange / 20
  498.                 Case [High]
  499.                     .SmallChange = .LargeChange / 15
  500.                 Case [Medium]
  501.                     .SmallChange = .LargeChange / 10
  502.                 Case [Low]
  503.                     .SmallChange = .LargeChange / 5
  504.             End Select
  505.         End With
  506.         With VScroll
  507.             NewMaxVal = CalcClientHeight - (UserControl.ScaleHeight - HScroll.Height)
  508.             'If NewMaxVal > 32767 Then NewMaxVal = 32767
  509.             .Max = NewMaxVal
  510.             If .Value > .Max Then .Value = .Max
  511.             .LargeChange = .Max
  512.             Select Case m_Sensibility
  513.                 Case [Highest]
  514.                     .SmallChange = .LargeChange / 20
  515.                 Case [High]
  516.                     .SmallChange = .LargeChange / 15
  517.                 Case [Medium]
  518.                     .SmallChange = .LargeChange / 10
  519.                 Case [Low]
  520.                     .SmallChange = .LargeChange / 5
  521.             End Select
  522.         End With
  523. End Select
  524.     If HScroll.Width >= (400) Then  'More than 400 px
  525.         'HScroll.SmallChange = HScroll.SmallChange * 0.5
  526.     ElseIf HScroll.Width < (400) And HScroll.Width >= (150) Then
  527.         HScroll.SmallChange = HScroll.SmallChange * 2
  528.     Else
  529.         HScroll.SmallChange = HScroll.SmallChange * 4
  530.     End If
  531.     
  532.     If VScroll.Height >= (400) Then   'More than 400 px
  533.         'VScroll.SmallChange = VScroll.SmallChange * 0.5
  534.     ElseIf VScroll.Height < (400) And VScroll.Height >= (150) Then
  535.         VScroll.SmallChange = VScroll.SmallChange * 2
  536.     Else
  537.         VScroll.SmallChange = VScroll.SmallChange * 4   ' les than 150
  538.     End If
  539.     
  540.  
  541. End Sub
  542.  
  543.  
  544.  
  545. Private Sub HScroll_Change()
  546. PositionContainedControls
  547. End Sub
  548. Private Sub HScroll_Scroll()
  549. PositionContainedControls
  550. End Sub
  551. Private Sub VScroll_Change()
  552. PositionContainedControls
  553. End Sub
  554. Private Sub VScroll_Scroll()
  555. PositionContainedControls
  556. End Sub
  557.  
  558.  
  559. Private Sub PositionContainedControls()
  560. On Error Resume Next
  561. Dim ctrl As Control
  562.  
  563. Select Case m_ScrollBars
  564.     Case vbSBNone
  565.  
  566.     Case vbHorizontal
  567.         For Each ctrl In UserControl.ContainedControls
  568.             ctrl.Move (ctrl.Left + HPrevValue) - HScroll.Value
  569.         Next
  570.         HPrevValue = HScroll.Value
  571.  
  572.     Case vbVertical
  573.         For Each ctrl In UserControl.ContainedControls
  574.             ctrl.Move ctrl.Left, (ctrl.Top + VPrevValue) - VScroll.Value
  575.         Next
  576.         VPrevValue = VScroll.Value
  577.     
  578.     Case vbBoth
  579.         For Each ctrl In UserControl.ContainedControls
  580.             ctrl.Move (ctrl.Left + HPrevValue) - HScroll.Value, (ctrl.Top + VPrevValue) - VScroll.Value
  581.         Next
  582.         HPrevValue = HScroll.Value
  583.         VPrevValue = VScroll.Value
  584. End Select
  585. End Sub
  586.  
  587.  
  588. Private Function OnArea() As Boolean
  589.     Dim mpos As POINTAPI
  590.     Dim oRect As RECT
  591.     GetCursorPos mpos
  592.     GetWindowRect Me.hWnd, oRect
  593.     If mpos.x >= oRect.Left And mpos.x <= oRect.Right And _
  594.         mpos.Y >= oRect.Top And mpos.Y <= oRect.Bottom Then
  595.         OnArea = True
  596.     Else
  597.         OnArea = False
  598.    End If
  599. End Function
  600.  
  601.  
  602. Public Sub ScrollUp()
  603. If OnArea = True Then
  604.     Select Case m_ScrollBehavior
  605.         Case [Normal]
  606.             If VScroll.Value >= VScroll.SmallChange Then
  607.                 VScroll.Value = VScroll.Value - VScroll.SmallChange
  608.             ElseIf VScroll.Value = VScroll.Min Then
  609.                 If HScroll.Value >= HScroll.SmallChange Then
  610.                     HScroll.Value = HScroll.Value - HScroll.SmallChange
  611.                 Else
  612.                     HScroll.Value = HScroll.Min
  613.                 End If
  614.             Else
  615.                 VScroll.Value = VScroll.Min
  616.             End If
  617.         Case [Middle], [Reverse]
  618.             If HScroll.Value >= HScroll.SmallChange Then
  619.                 HScroll.Value = HScroll.Value - HScroll.SmallChange
  620.             Else
  621.                 HScroll.Value = HScroll.Min
  622.                 If VScroll.Value >= VScroll.SmallChange Then
  623.                     VScroll.Value = VScroll.Value - VScroll.SmallChange
  624.                 Else
  625.                     VScroll.Value = VScroll.Min
  626.                 End If
  627.             End If
  628.     End Select
  629. End If
  630. End Sub
  631.  
  632.  
  633. Public Sub ScrollDown()
  634. If OnArea = True Then
  635.     Select Case m_ScrollBehavior
  636.         Case [Normal], [Middle]
  637.             If VScroll.Value <= VScroll.Max - VScroll.SmallChange Then
  638.                 VScroll.Value = VScroll.Value + VScroll.SmallChange
  639.             ElseIf VScroll.Value = VScroll.Max Then
  640.                 If HScroll.Value <= HScroll.Max - HScroll.SmallChange Then
  641.                     HScroll.Value = HScroll.Value + HScroll.SmallChange
  642.                 Else
  643.                     HScroll.Value = HScroll.Max
  644.                 End If
  645.             Else
  646.                 VScroll.Value = VScroll.Max
  647.             End If
  648.         Case [Reverse]
  649.             If HScroll.Value <= HScroll.Max - HScroll.SmallChange Then
  650.                 HScroll.Value = HScroll.Value + HScroll.SmallChange
  651.             Else
  652.                 HScroll.Value = HScroll.Max
  653.                 If VScroll.Value <= VScroll.Max - VScroll.SmallChange Then
  654.                     VScroll.Value = VScroll.Value + VScroll.SmallChange
  655.                 Else
  656.                     VScroll.Value = VScroll.Max
  657.                 End If
  658.             End If
  659.  
  660.     End Select
  661. End If
  662. End Sub
  663.  
  664. Private Sub UserControl_AmbientChanged(PropertyName As String)
  665.     bCancel = True              'IDE SAFE method, if go to debug mode,
  666.     FocusTimer.Enabled = False  'Stop ProcessMessages
  667. End Sub
  668.  
  669.  
  670. Private Sub ProcessMessages()
  671. Dim Message As msg
  672. On Error GoTo Err_Site
  673. Dim ctrl As Control
  674. Do While Not bCancel
  675.     If Not UserControl.Ambient.UserMode = True Then Exit Do
  676.     WaitMessage 'Wait For message
  677.     'if the mousewheel is used:
  678.     If PeekMessage(Message, UserControl.Parent.hWnd, WM_MOUSEWHEEL, WM_MOUSEWHEEL, PM_REMOVE) Then
  679.         If Message.wParam < 0 Then 'scroll up
  680.             For Each ctrl In UserControl.Parent.Controls
  681.                 If TypeOf ctrl Is IoxContainer Then
  682.                     ctrl.ScrollDown
  683.                 End If
  684.             Next
  685.         Else        'scroll down
  686.             For Each ctrl In UserControl.Parent.Controls
  687.                 If TypeOf ctrl Is IoxContainer Then
  688.                     ctrl.ScrollUp
  689.                 End If
  690.             Next
  691.         End If
  692.     End If
  693.     DoEvents
  694.  
  695.     Loop
  696. Err_Site:
  697.     If Err.Number = 398 Then bCancel = True
  698. End Sub
  699.  
  700.  
  701.  
  702.  
  703.  
  704. Private Sub FocusTimer_timer()
  705. On Error Resume Next
  706. If Not UserControl.Ambient.UserMode = True Then
  707.     FocusTimer.Enabled = False  'If in design view
  708.     Exit Sub
  709. End If
  710.  
  711. CurrCtrl.Name = UserControl.Parent.ActiveControl.Name
  712. CurrCtrl.Index = UserControl.Parent.ActiveControl.Index
  713.  
  714. 'Determine if control name or index has changed
  715. If (CurrCtrl.Name <> LastCtrl.Name) Or (CurrCtrl.Index <> LastCtrl.Index) Then
  716.     If CurrCtrl.Name <> LastCtrl.Name Then LastCtrl.Name = CurrCtrl.Name
  717.     If CurrCtrl.Index <> LastCtrl.Index Then LastCtrl.Index = CurrCtrl.Index
  718.     
  719.     Dim LastHwnd As Long
  720.     Dim CtrlContainer As Object
  721.     Dim CtrlPositionx  As Long
  722.     Dim CtrlPositionY  As Long
  723.  
  724.     CtrlPositionY = 0
  725.     
  726.     Set TempControl = UserControl.Parent.ActiveControl
  727.     Set CtrlContainer = TempControl.Container   'Parent of focused control
  728.     
  729.     Do
  730.         LastHwnd = CtrlContainer.hWnd
  731.         If LastHwnd = UserControl.hWnd Then Exit Do      'Parent is IoxContainer
  732.         CtrlPositionY = CtrlPositionY + CtrlContainer.Top
  733.         CtrlPositionx = CtrlPositionx + CtrlContainer.Left
  734.         Err.Clear
  735.         Set CtrlContainer = CtrlContainer.Container
  736.         If Err.Number <> 0 Then Exit Do         'No parent
  737.     Loop
  738. End If
  739.  
  740. If Not LastHwnd = Me.hWnd Then Exit Sub          'Active Control is't IoxContainer
  741.     
  742. Dim TempValue As Long, CtrlTop As Long, CtrlLeft As Long
  743.  
  744. 'Determine if control is out of vertical viewing range
  745.  
  746. CtrlTop = CtrlPositionY + TempControl.Top '- 50
  747. TempValue = TempControl.Height
  748. If TempValue > VScroll.Height Then TempValue = VScroll.Height - 175
  749. CtrlPositionY = CtrlPositionY + TempControl.Top + TempValue
  750. 'If the Control is outside of the Vertical viewing area, change the VScroll
  751. If CtrlTop < 0 Then
  752.     VScroll.Value = VScroll.Value + CtrlTop
  753. ElseIf CtrlPositionY > VScroll.Height Then
  754.     VScroll.Value = VScroll.Value + (CtrlPositionY - (VScroll.Height))
  755. End If
  756.  
  757. 'Determine if control is out of horizontal viewing range
  758. CtrlLeft = CtrlPositionx + TempControl.Left '- 50
  759. TempValue = TempControl.Width
  760. If TempValue > HScroll.Width Then TempValue = HScroll.Width - 175
  761. CtrlPositionx = CtrlPositionx + TempControl.Left + TempValue
  762. 'If the Control is outside of the Horizontal viewing area, change the HScroll
  763. If CtrlLeft < 0 Then
  764.     HScroll.Value = HScroll.Value + CtrlLeft
  765. ElseIf CtrlPositionx > HScroll.Width Then
  766.     HScroll.Value = HScroll.Value + (CtrlPositionx - (HScroll.Width))
  767. End If
  768.  
  769. End Sub
  770.